﻿using System;
using System.Diagnostics.Contracts;
using System.IO;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    /// <summary>
    /// future record type header.
    /// </summary>
    struct FrtHeader
    {
        public void Read (BinaryReader reader)
        {
            _rt = reader.ReadUInt16();
            _grbitFrt = (FrtFlags) reader.ReadUInt16();
            _reserved = reader.ReadUInt64();
        }
        public override string ToString()
        {
            return string.Format("{{rt = {0}, grBitfrt = {1}, reserved = {2}}}", _rt == 0?"INVALID!!":_rt.ToString(), _grbitFrt, _reserved);
        }
        internal ushort _rt;
        internal FrtFlags _grbitFrt;
        private ulong _reserved;

        public static FrtHeader Create(ushort rt_, FrtFlags grbitFrt_)
        {
            return new FrtHeader {_rt = rt_, _grbitFrt = grbitFrt_};
        }

        public void Write(BiffWriterWorkbookContext context)
        {
            this.Write((context.Writer));
            /*
            //\\Contract.Requires(_rt != 0);
            writer.Writer.Write(_rt);
            writer.Writer.Write((ushort)_grbitFrt);
            writer.Writer.Write(_reserved);*/
        }
        public void Write(BinaryWriter writer)
        {
            //\\Contract.Requires(_rt != 0);
            writer.Write(_rt);
            writer.Write((ushort)_grbitFrt);
            writer.Write(_reserved);
        }

        internal const int Size = 12;
    
    }
}